home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Documentation / d e v e l o p / Develop Issue 23 article / Geometry Sample / Shell src / FloatWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  7.3 KB  |  315 lines  |  [TEXT/MMCC]

  1.  
  2. #include "BuildControl.h"
  3.  
  4.  
  5.  
  6. #if defined(qUseDumpFile)
  7.     #include "DumpHeader.h"
  8. #else
  9.     #include <Resources.h>
  10. #endif
  11.  
  12. enum {
  13.     kFloaterPopup1        = 128,
  14.     kFloaterPopup2        = 129,
  15.     kFloaterPopup3        = 130,
  16.     kFloaterPopup4        = 131,
  17.  
  18.     kFloatingWindowType1 = 'FlWn'
  19. };
  20.  
  21. struct FloatWindowInfo {
  22.     Boolean lastVisibleState;
  23.     ControlHandle    geometryPopup;
  24.     ControlHandle    controlsPopup;
  25.     ControlHandle    rendererPopup;
  26.     ControlHandle    otraPopup;
  27. };
  28.  
  29. typedef struct FloatWindowInfo FloatWindowInfo, 
  30.             *FloatWindowInfoPtr, **FloaterInfoHndl;
  31.             
  32.  
  33. #include "WindowObj.h"
  34. #include "MainWindow.h"
  35. #include "Quickdraw3DSupport.h"
  36. #include "FloatingWindowSupport.h"
  37.  
  38. void FloatWindowDraw(WindowObjHndl obj, short depth);
  39. void FloatWindowClick(WindowObjHndl obj, EventRecord *event, long message);
  40. void FloatWindowActivate(WindowObjHndl obj, Boolean activate);
  41. void FloatWindowKeys(WindowObjHndl obj, long message, short mods);
  42. void FloatWindowNotify(WindowObjHndl obj, long message);
  43.  
  44. Boolean GetLastVisibleState(WindowPtr);
  45. void SetLastVisibleState(WindowPtr, Boolean);
  46.  
  47. void OpenFloatWindow(void);
  48. void DeleteAllItems(MenuHandle menu);
  49. void BuildPopup1(ControlHandle cntl);
  50.  
  51. void CreatePopupFloater(WindowObjHndl obj);
  52.  
  53.  
  54. WindowObjHndl pPopupFloater = NULL;
  55.  
  56. //-----------------------------------------------------------------------
  57. // A quick cheesy way to test that two different floaters works, too.
  58. //-----------------------------------------------------------------------
  59. void OpenFloatWindow()
  60. {
  61.     if (pPopupFloater == NULL)
  62.         pPopupFloater = NewObjWindow(130, kFloatingWindowType1, true, true, 
  63.                 FloatWindowDraw, FloatWindowKeys, FloatWindowClick, 
  64.                 FloatWindowActivate, FloatWindowNotify);
  65.     else
  66.         ShowThisWindow((*pPopupFloater)->window);
  67.  
  68. }
  69.  
  70. //-----------------------------------------------------------------------
  71.  
  72. void DeleteAllItems(MenuHandle menu)
  73. {
  74.     short items, count;
  75.     
  76.     items = CountMItems(menu);
  77.     
  78.     for (count = 0; count < items; count ++)
  79.         DeleteMenuItem(menu, 1);
  80. }
  81.  
  82. //-----------------------------------------------------------------------
  83.  
  84. void BuildPopup1(ControlHandle cntl)
  85. {
  86.     MenuHandle menu;
  87.     PopupPrivateDataHandle popupData;
  88.     short        index, maxItems = 4;
  89.     Str255        strList[4] ={     "\pPopup1Item1", "\pPopup1Item2", 
  90.                                 "\pPopup1Item3", "\pPopup1Item4"};
  91.  
  92.     index = 1;
  93.     popupData = (PopupPrivateDataHandle)(*cntl)->contrlData;
  94.     menu = (*popupData)->mHandle;
  95.     DeleteAllItems(menu);
  96.  
  97.     for (index = 1; index <= maxItems; index ++)
  98.         InsertMenuItem(menu, strList[index - 1], index);
  99.  
  100.     (*cntl)->contrlMax = maxItems;
  101.     (*cntl)->contrlMin = 1;
  102.     (*cntl)->contrlValue = 0;
  103. }
  104.  
  105. //-----------------------------------------------------------------------
  106.  
  107. void CreatePopupFloater(WindowObjHndl obj)
  108. {
  109.     FloaterInfoHndl    info;
  110.     ControlHandle    cntl1, cntl2, cntl3, cntl4;
  111.     WindowPtr        win;
  112.  
  113.     TextSize(9);
  114.     win = (*obj)->window;
  115.  
  116.     info = (FloaterInfoHndl) NewHandle(sizeof(FloatWindowInfo));    
  117.     require(info != NULL, InfoAllocFailed);
  118.  
  119.     cntl1 = cntl2 = cntl3 = cntl4 = NULL;
  120.     cntl1 = GetNewControl(kFloaterPopup1, win);
  121.     cntl2 = GetNewControl(kFloaterPopup2, win);
  122.     cntl3 = GetNewControl(kFloaterPopup3, win);
  123.     cntl4 = GetNewControl(kFloaterPopup4, win);
  124.     
  125.     require(((cntl1 != NULL) && (cntl2 != NULL) 
  126.             && (cntl3 != NULL) && (cntl4 != NULL)), PopupAllocFailed);
  127.  
  128. //    BuildPopup1(cntl1);    
  129.  
  130.     SetCtlValue(cntl1, 1);    ShowControl(cntl1);
  131.     SetCtlValue(cntl2, 1);    ShowControl(cntl2);
  132.     SetCtlValue(cntl3, 1);    ShowControl(cntl3);
  133.     SetCtlValue(cntl4, 1);    ShowControl(cntl4);
  134.  
  135.     (*info)->geometryPopup = cntl1;
  136.     (*info)->controlsPopup = cntl2;
  137.     (*info)->rendererPopup = cntl3;
  138.     (*info)->otraPopup = cntl4;
  139.     (*info)->lastVisibleState = false;
  140.     (*obj)->refCon = (unsigned long) info;
  141.  
  142. PopupAllocFailed:
  143. InfoAllocFailed:
  144.     return;
  145. }
  146.  
  147. //-----------------------------------------------------------------------
  148.  
  149. void FloatWindowNotify(WindowObjHndl obj, long message)
  150. {
  151.     FloaterInfoHndl    info;
  152.                 
  153.     switch (message) {
  154.         case kIdleNotification: 
  155.             break;
  156.  
  157.         case kCloseNotification:
  158.             break;
  159.  
  160.         case kCreateNotification:
  161.             CreatePopupFloater(obj);
  162.             break;
  163.         
  164.         case kDestroyNotification:
  165.             {
  166.                 info = (FloaterInfoHndl) (*obj)->refCon;
  167.                 
  168.                 if (info != NULL)
  169.                     DisposeHandle((Handle) info);
  170.             }
  171.             break;
  172.         
  173.         case kAdjustMenusNotification:
  174.             {
  175.                 MenuHandle     fileMenu = GetMenuHandle(kFileMenu),
  176.                             editMenu = GetMenuHandle(kEditMenu);
  177.  
  178.                 if (fileMenu != NULL) {
  179.                     EnableAllMenuItems(fileMenu);
  180.                     DisableItem(fileMenu, kNewItem);
  181.                 }
  182.                 
  183.                 if (editMenu != NULL) {                    
  184.                     EnableAllMenuItems(editMenu);
  185.                     DisableItem(editMenu, kUndoItem);
  186.                 }
  187.             }
  188.             break;
  189.     }    
  190. }
  191.  
  192. //-----------------------------------------------------------------------
  193.  
  194. void FloatWindowClick(WindowObjHndl obj, EventRecord *event, long message)
  195. {
  196.     Point            localPt;
  197.     ControlHandle    cntl;
  198.     short            menuItem;
  199.     WindowPtr        win = (*obj)->window;
  200.     FloaterInfoHndl    info;
  201.     
  202.     info = (FloaterInfoHndl) (*obj)->refCon;
  203.  
  204.     if (message == inContent) {
  205.         localPt = event->where;
  206.         GlobalToLocal(&localPt);
  207.         (void) FindControl(localPt, win, &cntl);
  208.  
  209.         if (cntl != NULL) {
  210.             WindowPtr    threeDeeWindow;
  211.  
  212.             (void) TrackControl(cntl, localPt, (ControlActionUPP) -1);
  213.  
  214.             threeDeeWindow = FrontNonFloatingWindow();
  215.             
  216.             if ((threeDeeWindow != NULL) && (Is3DWindow(threeDeeWindow))) {
  217.                 menuItem = GetControlValue(cntl);
  218.             
  219.                 if (cntl == (*info)->geometryPopup)
  220.                     SetWindowGeometry(threeDeeWindow, menuItem);
  221.                 
  222.                 else if (cntl == (*info)->controlsPopup)
  223.                     SetWindowShading(threeDeeWindow, menuItem);
  224.                 
  225.                 else if (cntl == (*info)->rendererPopup) {
  226.                     PopupPrivateDataHandle    priv;
  227.                     
  228.                     priv = (PopupPrivateDataHandle) (*cntl)->contrlData;
  229.                     SetWindowRenderer( threeDeeWindow, menuItem );
  230.                 }
  231.             }        
  232.         }
  233.     }
  234. }
  235.  
  236. //-----------------------------------------------------------------------
  237.  
  238. void FloatWindowKeys(WindowObjHndl obj, long message, short mods)
  239. {
  240. #pragma unused (mods, obj)
  241.     short        code = (message & charCodeMask) & 0xFF;
  242. }
  243.  
  244. //-----------------------------------------------------------------------
  245.  
  246. void FloatWindowActivate(WindowObjHndl obj, Boolean activate)
  247. {
  248. #pragma unused (activate, obj)
  249. }
  250.  
  251. //-----------------------------------------------------------------------
  252.  
  253. void FloatWindowDraw(WindowObjHndl obj, short depth)
  254. {
  255. #pragma unused (depth)
  256.     WindowPtr    win;
  257.  
  258.     win = (*obj)->window;
  259.     UpdateControls(win, win->visRgn);
  260.  
  261.     ForeColor(blackColor);
  262.     MoveTo(5, 15);
  263.     
  264.     if ((*obj)->type == kFloatingWindowType1)
  265.         DrawString("\pFloat 1");
  266. }
  267.  
  268. //-----------------------------------------------------------------------
  269.  
  270. Boolean GetLastVisibleState(WindowPtr win)
  271. {
  272.     FloaterInfoHndl info;
  273.     WindowObjHndl    obj;
  274.  
  275.     require(IsAppWindow(win), NotAnAppWindow);
  276.  
  277.     obj = (WindowObjHndl) GetWRefCon(win);    
  278.     require(obj != NULL, WindowObjHndlIsNULL);
  279.  
  280.     info = (FloaterInfoHndl) (*obj)->refCon;
  281.     require(info != NULL, FloaterInfoHndlIsNULL);
  282.     
  283.     return (*info)->lastVisibleState;
  284.  
  285.     //
  286.     // If we got here, something went terribly wrong
  287.     //
  288. FloaterInfoHndlIsNULL:
  289. WindowObjHndlIsNULL:
  290. NotAnAppWindow:
  291.     return false;    
  292. }
  293.  
  294. //-----------------------------------------------------------------------
  295.  
  296. void SetLastVisibleState(WindowPtr win, Boolean visible)
  297. {
  298.     FloaterInfoHndl info;
  299.     WindowObjHndl    obj;
  300.  
  301.     require(IsAppWindow(win), NotAnAppWindow);
  302.  
  303.     obj = (WindowObjHndl) GetWRefCon(win);    
  304.     require(obj != NULL, WindowObjHndlIsNULL);
  305.  
  306.     info = (FloaterInfoHndl) (*obj)->refCon;
  307.     require(info != NULL, FloaterInfoHndlIsNULL);
  308.     (*info)->lastVisibleState = visible;
  309.  
  310. FloaterInfoHndlIsNULL:
  311. WindowObjHndlIsNULL:
  312. NotAnAppWindow:
  313.     return;
  314. }
  315.